import axios from '@/utils/http';
import base from './base';

export default {
  // 注册新用户并绑定
  create(params) {
    return axios.post(
      `${base.sq}/oauth2`,
      {
        phone: params.phone,
        code: params.code,
        open_id: params.openId,
        type: params.type,
      },
    );
  },
  // 绑定已有用户 (先走登录获取token）
  update(params) {
    return axios.put(
      `${base.sq}/oauth2/bind_existing_user`, // 后端要求这么写
      {
        open_id: params.openId,
        type: params.type,
      },
    );
  },
  // 已绑定直接登录
  directSignIn(params) {
    return axios.post(
      `${base.sq}/oauth2/login`,
      {
        open_id: params.openId,
        type: params.type,
      },
    );
  },
  // 获取绑定信息
  index() {
    return axios.get(`${base.sq}/oauth2`);
  },
  // 解绑
  destroy(params) {
    return axios.delete(
      `${base.sq}/oauth2/${params.id}`,
      {
        params: {
          phone: params.phone,
          code: params.code,
          id: params.id,
        },
      },
    );
  },
};
